Skip to content

Fix Supabase key validation and consolidate frontend state management#232

Merged
Wirasm merged 3 commits intomainfrom
fix/supabase-key-validation-and-state-consolidation
Aug 18, 2025
Merged

Fix Supabase key validation and consolidate frontend state management#232
Wirasm merged 3 commits intomainfrom
fix/supabase-key-validation-and-state-consolidation

Conversation

@Wirasm
Copy link
Copy Markdown
Collaborator

@Wirasm Wirasm commented Aug 15, 2025

Pull Request

Summary

This PR addresses a critical configuration issue where users accidentally use Supabase ANON (public) keys instead of SERVICE keys, causing database write failures. It adds backend validation to detect and prevent this misconfiguration, while also simplifying frontend state management following KISS principles.

Changes Made

  • Add JWT-based validation to detect anon vs service keys at backend startup
  • Fail fast with clear error messages when incorrect key type is detected
  • Consolidate frontend state management - MainLayout is now single source of truth
  • Remove duplicate state tracking and sessionStorage polling
  • Add comprehensive error display component when backend fails to start
  • Improve .env.example documentation with detailed key selection guidance
  • Add comprehensive test coverage for validation logic
  • Remove unused test results checking that caused 404 errors

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Code refactoring
  • Documentation update

Affected Services

  • Frontend (React UI)
  • Server (FastAPI backend)
  • MCP Server (Model Context Protocol)
  • Agents (PydanticAI service)
  • Database (migrations/schema)
  • Docker/Infrastructure
  • Documentation site

Testing

  • All existing tests pass
  • Added new tests for new functionality
  • Manually tested affected user flows
  • Docker builds succeed for all services

Test Evidence

# Python validation tests
cd python && uv run pytest tests/test_supabase_validation.py -v
# Result: 11 passed

# Frontend tests
cd archon-ui-main && npm test -- --run
# Result: Test Files 4 passed (4), Tests 39 passed (39)

# Backend tests
cd python && uv run pytest tests/test_settings_api.py -v
# Result: All tests pass

Checklist

  • My code follows the service architecture patterns
  • If using an AI coding assistant, I used the CLAUDE.md rules
  • I have added tests that prove my fix/feature works
  • All new and existing tests pass locally
  • My changes generate no new warnings
  • I have updated relevant documentation
  • I have verified no regressions in existing features

Breaking Changes

None - the system remains backward compatible while adding validation warnings.

Additional Notes

Key Improvements:

  1. User Protection: Prevents a very common Supabase configuration mistake
  2. Clear Guidance: Detailed error messages with exact steps to fix
  3. Simplified State: Removed ~50 lines of complex state synchronization code
  4. Better Performance: Eliminated polling overhead

Files Added:

  • archon-ui-main/src/components/BackendStartupError.tsx - Error display component
  • python/tests/test_supabase_validation.py - Comprehensive validation tests

Critical Fixes Applied:

  • Used python-jose (already in dependencies) instead of requiring PyJWT
  • Made unknown key roles fail fast per alpha principles
  • Fixed JWT validation to properly skip all checks when only examining role

The implementation follows the "warn but don't break" approach - providing helpful validation while maintaining backward compatibility.

Wirasm added 2 commits August 16, 2025 00:10
- Add backend validation to detect and warn about anon vs service keys
- Prevent startup with incorrect Supabase key configuration
- Consolidate frontend state management following KISS principles
- Remove duplicate state tracking and sessionStorage polling
- Add clear error display when backend fails to start
- Improve .env.example documentation with detailed key selection guide
- Add comprehensive test coverage for validation logic
- Remove unused test results checking to eliminate 404 errors

The implementation now warns users about key misconfiguration while
maintaining backward compatibility. Frontend state is simplified with
MainLayout as the single source of truth for backend status.
- Use python-jose (already in dependencies) instead of PyJWT for JWT decoding
- Make unknown Supabase key roles fail fast per alpha principles
- Skip all JWT validations (not just signature) when checking role
- Update tests to expect failure for unknown roles

Fixes:
- No need to add PyJWT dependency - python-jose provides JWT functionality
- Unknown key types now raise ConfigurationError instead of warning
- JWT decode properly skips all validations to only check role claim
@Wirasm
Copy link
Copy Markdown
Collaborator Author

Wirasm commented Aug 15, 2025

resolves #223

@Wirasm
Copy link
Copy Markdown
Collaborator Author

Wirasm commented Aug 15, 2025

resolves #204

@Wirasm Wirasm requested a review from coleam00 August 15, 2025 21:34
@coleam00
Copy link
Copy Markdown
Owner

@Wirasm This is great, much needed so thank you! However, when I start up Archon on this PR I get this error in the Archon-UI container:

2025-08-16 06:23:51 /usr/local/bin/docker-entrypoint.sh: exec: line 11: /app/start.sh: not found

Might be best to not change the Dockerfile for the frontend.

- Rolled back to match main branch Dockerfile
- Removed 3-second sleep script that was added for backend readiness
- Container now runs npm directly without intermediate script
- Tested and verified all services start correctly without the delay
@Wirasm
Copy link
Copy Markdown
Collaborator Author

Wirasm commented Aug 18, 2025

@coleam00 please test it again

@Wirasm
Copy link
Copy Markdown
Collaborator Author

Wirasm commented Aug 18, 2025

solves: #286

Copy link
Copy Markdown
Owner

@coleam00 coleam00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect now!

@Wirasm Wirasm merged commit 667cae2 into main Aug 18, 2025
7 checks passed
@Wirasm Wirasm deleted the fix/supabase-key-validation-and-state-consolidation branch August 18, 2025 18:19
POWERFULMOVES added a commit to POWERFULMOVES/PMOVES-Archon that referenced this pull request Feb 12, 2026
…ions-health

Feat/ghcr integrations health
coleam00 pushed a commit that referenced this pull request Apr 7, 2026
…237)

* Fix: Add stale workflow cleanup and defense-in-depth error handling

Problem: Workflows could get stuck in "running" state indefinitely when
the async generator disconnected but the AI subprocess continued working.
This blocked new workflow invocations with "Workflow already running" errors.

Root cause: No cleanup mechanism existed for workflows that failed to
complete due to disconnection between the executor and the Claude SDK.

Solution (defense-in-depth):
1. Activity-based staleness detection: Workflows inactive for 15+ minutes
   are auto-failed when a new workflow is triggered on the same conversation
2. Top-level error handling: All errors in workflow execution are caught
   and the workflow is properly marked as failed (prevents stuck state)
3. Manual cancel command: /workflow cancel lets users force-fail stuck
   workflows immediately

Changes:
- Add last_activity_at column via migration for staleness tracking
- Add updateWorkflowActivity() to track activity during execution
- Add staleness check before blocking concurrent workflows
- Wrap workflow execution in try-catch to ensure failure is recorded
- Add /workflow cancel subcommand to command handler
- Update test to match new error handling behavior

Fixes #232

* docs: Add /workflow cancel command to documentation

* Improve error handling and add comprehensive tests for stale workflow cleanup

Error handling improvements:
- Add workflow ID and error context to updateWorkflowActivity logs
- Add stack trace, error name, and cause to top-level catch block
- Separate DB failure recording from file logging for clearer error messages
- Add try-catch around staleness cleanup with user-facing error message
- Check sendCriticalMessage return value and log when user not notified

Test coverage additions:
- Add staleness detection tests (stale vs non-stale, fallback to started_at)
- Add /workflow cancel command tests
- Add updateWorkflowActivity function tests (including non-throwing behavior)

All 845 tests pass, type-check clean, lint clean.
coleam00 pushed a commit that referenced this pull request Apr 7, 2026
* Fix: PR worktrees use actual branch for same-repo PRs (#232)

When creating a worktree for a PR review, the system was always creating
a synthetic branch (`pr-N-review`) instead of using the PR's actual branch.
This caused confusion when pushing changes back to the PR, as commits went
to an orphan branch instead of updating the PR.

Changes:
- Add `isForkPR` field to IsolationHints and IsolationRequest
- Add fork detection in GitHub adapter (compares head.repo vs base.repo)
- Update createFromPR() to use actual branch for same-repo PRs
- Fork PRs still use synthetic branch (can't push to forks anyway)
- Update generateBranchName() to return actual PR branch for same-repo PRs
- Add tests for same-repo vs fork PR behavior

Fixes #232

* docs: Update PR worktree behavior documentation for fork vs same-repo PRs

* Address PR review findings: error handling and test coverage

1. **Error handling improvements**:
   - Add `prFetchFailed` flag to `IsolationHints` for degraded mode detection
   - Distinguish transient vs non-transient failures in PR fetch error handling
   - Make upstream tracking failure non-fatal (worktree still usable)

2. **Documentation**:
   - Add comment clarifying deleted fork edge case (null head.repo)

3. **Test coverage**:
   - Add fork detection unit tests (same-repo, fork, deleted fork, case sensitivity)
   - Add orchestrator integration tests for isForkPR pass-through

Addresses review feedback from PR #238.

* Simplify error handling in PR fetch logic

- Remove code duplication in logging branches
- Use dynamic function selection for log level
- Remove redundant boolean fields from log output
- Consolidate comments
Tyone88 pushed a commit to Tyone88/Archon that referenced this pull request Apr 16, 2026
…oleam00#237)

* Fix: Add stale workflow cleanup and defense-in-depth error handling

Problem: Workflows could get stuck in "running" state indefinitely when
the async generator disconnected but the AI subprocess continued working.
This blocked new workflow invocations with "Workflow already running" errors.

Root cause: No cleanup mechanism existed for workflows that failed to
complete due to disconnection between the executor and the Claude SDK.

Solution (defense-in-depth):
1. Activity-based staleness detection: Workflows inactive for 15+ minutes
   are auto-failed when a new workflow is triggered on the same conversation
2. Top-level error handling: All errors in workflow execution are caught
   and the workflow is properly marked as failed (prevents stuck state)
3. Manual cancel command: /workflow cancel lets users force-fail stuck
   workflows immediately

Changes:
- Add last_activity_at column via migration for staleness tracking
- Add updateWorkflowActivity() to track activity during execution
- Add staleness check before blocking concurrent workflows
- Wrap workflow execution in try-catch to ensure failure is recorded
- Add /workflow cancel subcommand to command handler
- Update test to match new error handling behavior

Fixes coleam00#232

* docs: Add /workflow cancel command to documentation

* Improve error handling and add comprehensive tests for stale workflow cleanup

Error handling improvements:
- Add workflow ID and error context to updateWorkflowActivity logs
- Add stack trace, error name, and cause to top-level catch block
- Separate DB failure recording from file logging for clearer error messages
- Add try-catch around staleness cleanup with user-facing error message
- Check sendCriticalMessage return value and log when user not notified

Test coverage additions:
- Add staleness detection tests (stale vs non-stale, fallback to started_at)
- Add /workflow cancel command tests
- Add updateWorkflowActivity function tests (including non-throwing behavior)

All 845 tests pass, type-check clean, lint clean.
Tyone88 pushed a commit to Tyone88/Archon that referenced this pull request Apr 16, 2026
* Fix: PR worktrees use actual branch for same-repo PRs (coleam00#232)

When creating a worktree for a PR review, the system was always creating
a synthetic branch (`pr-N-review`) instead of using the PR's actual branch.
This caused confusion when pushing changes back to the PR, as commits went
to an orphan branch instead of updating the PR.

Changes:
- Add `isForkPR` field to IsolationHints and IsolationRequest
- Add fork detection in GitHub adapter (compares head.repo vs base.repo)
- Update createFromPR() to use actual branch for same-repo PRs
- Fork PRs still use synthetic branch (can't push to forks anyway)
- Update generateBranchName() to return actual PR branch for same-repo PRs
- Add tests for same-repo vs fork PR behavior

Fixes coleam00#232

* docs: Update PR worktree behavior documentation for fork vs same-repo PRs

* Address PR review findings: error handling and test coverage

1. **Error handling improvements**:
   - Add `prFetchFailed` flag to `IsolationHints` for degraded mode detection
   - Distinguish transient vs non-transient failures in PR fetch error handling
   - Make upstream tracking failure non-fatal (worktree still usable)

2. **Documentation**:
   - Add comment clarifying deleted fork edge case (null head.repo)

3. **Test coverage**:
   - Add fork detection unit tests (same-repo, fork, deleted fork, case sensitivity)
   - Add orchestrator integration tests for isForkPR pass-through

Addresses review feedback from PR coleam00#238.

* Simplify error handling in PR fetch logic

- Remove code duplication in logging branches
- Use dynamic function selection for log level
- Remove redundant boolean fields from log output
- Consolidate comments
joaobmonteiro pushed a commit to joaobmonteiro/Archon that referenced this pull request Apr 26, 2026
…oleam00#237)

* Fix: Add stale workflow cleanup and defense-in-depth error handling

Problem: Workflows could get stuck in "running" state indefinitely when
the async generator disconnected but the AI subprocess continued working.
This blocked new workflow invocations with "Workflow already running" errors.

Root cause: No cleanup mechanism existed for workflows that failed to
complete due to disconnection between the executor and the Claude SDK.

Solution (defense-in-depth):
1. Activity-based staleness detection: Workflows inactive for 15+ minutes
   are auto-failed when a new workflow is triggered on the same conversation
2. Top-level error handling: All errors in workflow execution are caught
   and the workflow is properly marked as failed (prevents stuck state)
3. Manual cancel command: /workflow cancel lets users force-fail stuck
   workflows immediately

Changes:
- Add last_activity_at column via migration for staleness tracking
- Add updateWorkflowActivity() to track activity during execution
- Add staleness check before blocking concurrent workflows
- Wrap workflow execution in try-catch to ensure failure is recorded
- Add /workflow cancel subcommand to command handler
- Update test to match new error handling behavior

Fixes coleam00#232

* docs: Add /workflow cancel command to documentation

* Improve error handling and add comprehensive tests for stale workflow cleanup

Error handling improvements:
- Add workflow ID and error context to updateWorkflowActivity logs
- Add stack trace, error name, and cause to top-level catch block
- Separate DB failure recording from file logging for clearer error messages
- Add try-catch around staleness cleanup with user-facing error message
- Check sendCriticalMessage return value and log when user not notified

Test coverage additions:
- Add staleness detection tests (stale vs non-stale, fallback to started_at)
- Add /workflow cancel command tests
- Add updateWorkflowActivity function tests (including non-throwing behavior)

All 845 tests pass, type-check clean, lint clean.
joaobmonteiro pushed a commit to joaobmonteiro/Archon that referenced this pull request Apr 26, 2026
* Fix: PR worktrees use actual branch for same-repo PRs (coleam00#232)

When creating a worktree for a PR review, the system was always creating
a synthetic branch (`pr-N-review`) instead of using the PR's actual branch.
This caused confusion when pushing changes back to the PR, as commits went
to an orphan branch instead of updating the PR.

Changes:
- Add `isForkPR` field to IsolationHints and IsolationRequest
- Add fork detection in GitHub adapter (compares head.repo vs base.repo)
- Update createFromPR() to use actual branch for same-repo PRs
- Fork PRs still use synthetic branch (can't push to forks anyway)
- Update generateBranchName() to return actual PR branch for same-repo PRs
- Add tests for same-repo vs fork PR behavior

Fixes coleam00#232

* docs: Update PR worktree behavior documentation for fork vs same-repo PRs

* Address PR review findings: error handling and test coverage

1. **Error handling improvements**:
   - Add `prFetchFailed` flag to `IsolationHints` for degraded mode detection
   - Distinguish transient vs non-transient failures in PR fetch error handling
   - Make upstream tracking failure non-fatal (worktree still usable)

2. **Documentation**:
   - Add comment clarifying deleted fork edge case (null head.repo)

3. **Test coverage**:
   - Add fork detection unit tests (same-repo, fork, deleted fork, case sensitivity)
   - Add orchestrator integration tests for isForkPR pass-through

Addresses review feedback from PR coleam00#238.

* Simplify error handling in PR fetch logic

- Remove code duplication in logging branches
- Use dynamic function selection for log level
- Remove redundant boolean fields from log output
- Consolidate comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants